package com.example.schooljava.service.impl;

import com.example.schooljava.pojo.entity.Student;
import com.example.schooljava.mapper.StudentMapper;
import com.example.schooljava.pojo.bo.StudentsBO;
import com.example.schooljava.service.StudentService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.schooljava.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author LDH
 * @since 2022/08/11
 */
@Service
public class StudentServiceImpl extends ServiceImpl<StudentMapper, Student> implements StudentService {

    @Autowired
    private StudentMapper studentMapper;

    /**
     * 功能描述: 学生注册<br>
     * @Param: [student]
     * @Return: com.example.schooljava.util.Result
     * @Author: LDH
     * @Date: 2022/8/18 23:09
     */
    @Override
    public Result register(Student student) {
        save(student);
        return new Result<>().OK(true,"注册成功!");
    }

    /**
     * 功能描述: 获取所有学生信息<br>
     * @Param: [query]
     * @Return: com.example.schooljava.util.Result
     * @Author: LDH
     * @Date: 2022/8/18 23:09
     */
    @Override
    public Result findAllStudents(StudentsBO studentsBO) {
        return new Result<>().Huoqu_OK(studentMapper.findAllStudents(studentsBO));
    }

    /**
     * 功能描述: 批量删除学生信息<br>
     * @Param: [list]
     * @Return: com.example.schooljava.util.Result
     * @Author: LDH
     * @Date: 2022/8/18 23:16
     */
    @Override
    public Result delStudent(ArrayList<String> list) {
        for (String l : list) {
            for (Student student : list()) {
                if (Long.parseLong(l) == student.getSno())
                    removeById(Long.parseLong(l));
            }
        }
        return new Result<>().OK_Back(true,"删除成功！",findAllStudents(new StudentsBO()));
    }
}
